package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.admin.service.impl.AdChannelServiceImpl;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理" ,tags = "channel", description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelServiceImpl adChannelService;

    @Override
    @PostMapping("/list")
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "dto",type ="TbAdminDto",value = "查询名称")

    // 多个参数用以下注解
    //@ApiOperation(value = "查询商品列表",notes = "分页查询")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page",type ="Integer",value = "页码"),
    //        @ApiImplicitParam(name = "rows",type ="Integer",value = "条数")
    //  }
    //)
    public ResponseResult findByNameAndPage(ChannelDto dto) {
        ResponseResult responseResult = adChannelService.findByNameAndPage(dto);
        return responseResult;
    }

    @Override
    @PostMapping("/save")
    @ApiOperation(value = "添加频道信息")
    @ApiImplicitParam(name = "channel",type ="AdChannel",value = "添加")
    public ResponseResult save(@RequestBody AdChannel channel) {
        ResponseResult responseResult = adChannelService.insert(channel);
        return responseResult;
    }

    @Override
    @PostMapping("/update")
    @ApiOperation(value = "修改频道信息")
    @ApiImplicitParam(name = "adChannel",type ="AdChannel",value = "修改")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        ResponseResult responseResult = adChannelService.update(adChannel);
        return responseResult;

    }


    @Override
    @GetMapping("/del/{id}")
    @ApiOperation(value = "删除频道信息")
    @ApiImplicitParam(name = "id",type ="Integer",value = "删除")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        ResponseResult responseResult = adChannelService.deleteById(id);
        return responseResult;
    }

    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        return ResponseResult.okResult(adChannelService.list());
    }

}